﻿//        Another Demo from Andy L. & MissedMemo.com
// Borrow whatever code seems useful - just don't try to hold
// me responsible for any ill effects. My demos sometimes use
// licensed images which CANNOT legally be copied and reused.

using System;
using System.Windows.Data;
using System.Windows.Media;

using MissedMemo.MeatAndCheeseDisc.OrderMonitor.OrderProcessing;
using MissedMemo.MeatAndCheeseDisc.UIHelperClasses;


namespace MissedMemo.MeatAndCheeseDisc.OrderMonitor
{
    public class ElapsedTimeToColorConverter : IValueConverter
    {
        public Brush OrderOnScheduleColor { get; set; }
        public Brush OrderOnScheduleSelectedColor { get; set; }
        public Brush OrderScheduleWarningColor { get; set; }
        public Brush OrderScheduleOverdueColor { get; set; }

        
        public object Convert( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )
        {
            bool isSelected = System.Convert.ToBoolean( parameter );
            Brush brColor = isSelected ? OrderOnScheduleSelectedColor : OrderOnScheduleColor;

            TimeSpan elapsedTime = (TimeSpan)value;

            if( elapsedTime != null )
            {
                if( elapsedTime > OrderTimer.ScheduleErrorThreshold )
                    brColor = OrderScheduleOverdueColor;

                else if( elapsedTime > OrderTimer.ScheduleWarningThreshold )
                    brColor = OrderScheduleWarningColor;
            }

            return brColor;
        }


        public object ConvertBack( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )
        {
            throw new NotImplementedException();
        }
    }
}
